package com.bgs.controller;

import com.bgs.pojo.CurriculumSubject;
import com.bgs.pojo.studentInformation;
import com.bgs.pojo.vo.CurriculumSubjectVo;
import com.bgs.pojo.vo.studentInformationVO;
import com.bgs.service.CurService;
import com.bgs.utils.MyContent;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 梁玉杰
 * @Date: 2021/8/30 09:04
 * @Description: s
 */
@Controller
public class CurController {

    @Autowired
    private CurService curService;

    Logger log = LogManager.getLogger();


    //全查+模糊差------新技术（因为需要返回map集合，但是呢，不推荐用map）
    @RequestMapping("/CurfindAllormodil")
    @ResponseBody
    public Map<String,Object> CurfindAllormodil(@RequestBody CurriculumSubjectVo cVO){

        //模糊查询前端传过来的数据
        log.info("模糊查询前端传过来的数据studentInformationVO"+cVO);
        Map<String,Object> m = new HashMap<>();
        //设置分页信息(当前页码，每页显示数量)
        PageHelper.startPage(cVO.getPage(),cVO.getLimit());
        //调用分页查询账单类列表的方法
        List<CurriculumSubject> curList = curService.findAll(cVO);
        //创建分页对象
        PageInfo<CurriculumSubject> pageInfo = new PageInfo<CurriculumSubject>(curList);
        // JSONObject jsonObj = JSONObject.parseObject(sJson);
        // m = jsonObj; json对象转成map
        log.info("List<studentInformation>:::"+pageInfo);
        m.put(MyContent.CODE,0);
        m.put(MyContent.MSG,"查询成功！");
        m.put(MyContent.COUNT,pageInfo.getTotal());
        m.put(MyContent.DATA,pageInfo.getList());


        return m;
    }

    //全查+模糊差------新技术（因为需要返回map集合，但是呢，不推荐用map）
//    @RequestMapping("/StudentfindAllormodil1")
//    @ResponseBody
//    public DataGridViewResult StudentfindAllormodil1(@RequestBody studentInformationVO sVO){
//        //设置分页信息(当前页码，每页显示数量)
//        PageHelper.startPage(sVO.getPage(),sVO.getLimit());
//        //调用分页查询账单类列表的方法
//        List<studentInformation> slist = studenService.findAll(sVO);
//        //创建分页对象
//        PageInfo<studentInformation> pageInfo = new PageInfo<studentInformation>(slist);
//        return new DataGridViewResult(pageInfo.getTotal(),pageInfo.getList());
//    }




    @RequestMapping("/addCur")
    @ResponseBody
    public Map<String,Object> addCur(@RequestBody CurriculumSubject curriculumSubject){
        log.info("添加的"+curriculumSubject);
        Map<String,Object> m = new HashMap<String,Object>();
        if(curService.insertSelective(curriculumSubject) > 0){
            m.put("success",true);
            m.put("message","添加成功");
        }else{
            m.put("success",false);
            m.put("message","添加失败");
        }
        return m;
    }

    //修改
    @RequestMapping("/updCur")
    @ResponseBody
    public Map<String,Object> updCur(@RequestBody CurriculumSubject cur){
        Map<String,Object> m = new HashMap<>();
        log.info("修改的VO"+cur);
        if(curService.updateByPrimaryKeySelective(cur) > 0){
            m.put("success",true);
            m.put("message","修改成功");
        }else{
            m.put("success",false);
            m.put("message","修改 失败");
        }
        return m;
    }



//    @GetMapping("/getKechengByTid.action")
//    @ResponseBody
//    public List<Kecheng> getKecheng() throws Exception {
//        List<Kecheng> list = collectionService.getKecheng();
//        return list;
//    }


}
